package com.simon.netty.demo2;

import com.simon.netty.demo2.Utils.ByteBufUtils;
import com.simon.netty.demo2.po.Person;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * Created by changf on 2017/7/14.
 */
public class PersonEncoder  extends MessageToByteEncoder<Person>{
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, Person person, ByteBuf byteBuf) throws Exception {
        byte[] bytes = ByteBufUtils.objectToByte(person);
        byteBuf.writeBytes(bytes);
        channelHandlerContext.flush();
    }
}
